package com.retch.wenchengmao.recodeauthutils.listview;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.View;
import android.widget.AdapterView;
import android.widget.EditText;
import android.widget.ListView;
import android.widget.SearchView;
import android.widget.Toast;
import com.retch.wenchengmao.recodeauthutils.R;
import com.retch.wenchengmao.recodeauthutils.listview.entity.Info;

import java.util.ArrayList;
import java.util.List;

/**
 * author:wenchengmao
 * time:  2017/3/28.
 * email: wenchengmao@yeah.net
 */

public class ListViewActivity extends AppCompatActivity {
    private EditText search;
    MyAdapter myAdapter;
    List<Info> list=new ArrayList<>();
    private ListView listView;
    public void onCreate(Bundle savesInstanceState)
    {
        super.onCreate(savesInstanceState);
        setContentView(R.layout.activity_list_view);
        listView=(ListView)findViewById(R.id.list_view);
        search=(EditText)findViewById(R.id.search);
        getInfo();
        myAdapter=new MyAdapter(ListViewActivity.this,list);
        listView.setAdapter(myAdapter);
        myAdapter.notifyDataSetChanged();
        search.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {

            }

            @Override
            public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
                myAdapter.getFilter().filter(charSequence);
            }

            @Override
            public void afterTextChanged(Editable editable) {

            }
        });

        click();
    }

    public void click()
    {
        listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
                Toast.makeText(ListViewActivity.this,"点击了item",Toast.LENGTH_LONG).show();
            }
        });

    }

    public void getInfo() {
        Info info1 = new Info("阿大", 800.0, "IT软件设计师");
        Info info2 = new Info("阿二", 700.0, "android软件设计师");
        Info info3 = new Info("阿三", 500.0, "IOS软件设计师");
        Info info4 = new Info("阿四", 300.0, "C#软件设计师");
        list.add(info1);
        list.add(info2);
        list.add(info3);
        list.add(info4);
    }

}
